



<cfoutput>

<cfset today = now()>
<cfset mytime = timeformat(now(), "hh:mm:ss tt")>

<cfset clockintime = timeformat(now(), "HHMM")>

<cfparam name="mytotal" default="0">



 <cfquery name="CheckUser" datasource="#dsn#">
	SELECT * 
	FROM tblpasswords
	WHERE IDN = #form.Display#
</cfquery>



 <cfquery name="Checkstatus" datasource="#dsn#">
	SELECT *
	FROM tblemp
	WHERE username = #CheckUser.username#
    order by TransType DESC
</cfquery>




<CFIF #Checkstatus.RECORDCOUNT# LTE 0>



<CFSET STATUS = "CLOCKED OUT">

</CFIF>



<CFIF #Checkstatus.RECORDCOUNT# GTE 1 AND #Checkstatus.TransType# EQ "CLOCKED IN">
 <cfquery name="clockedin" datasource="#dsn#">
	SELECT *
	FROM tblemp
	WHERE username = #CheckUser.username# and TransType = 'CLOCKED IN'
    order by TransType DESC
</cfquery>


<cfoutput query="clockedin" maxrows="1">

<CFSET mydate = "#TransDate#">

</cfoutput>

<CFSET STATUS = "CLOCKED OUT">

<cfset clockoutime = timeformat(now(), "HHMM")>

<cfset clockintime = timeformat(mydate, "HHMM")>



<cfset mytotal =  #clockoutime# - #clockintime#>

</CFIF>

<CFIF #Checkstatus.RECORDCOUNT# GTE 1 AND #MYTYPE# EQ "CLOCKED OUT">
<CFSET STATUS = "CLOCKED IN">

</CFIF>





<cfquery datasource="#dsn#">
INSERT INTO tblemp(TransDate, TransTime, TransType, username, TimeTotal)
VALUES(<cfqueryparam cfsqltype="cf_sql_timestamp" value="#today#">,
'#mytime#',
'#STATUS#',
'#CheckUser.USERNAME#',
<cfif mytotal lte 0>0<cfelse>#mytotal#</cfif>
)
</cfquery>



<cflocation url="login.cfm">



</cfoutput>
